home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FIRE_TUT.ZIP / TUTORIAL.DOC < prev   
Text File  |  1995-08-11  |  6KB  |  145 lines

  1.  
  2.  _____                    ______                   Wikki -
  3. //----                    \__ __\                       Fragmentaria '95
  4. ||---                __      ||               __ 
  5. ||    |  _-   _ _   /_/      ||     _ ___  _  |_|
  6. \|    | |--\ | | | |__       \|  |_/|  |  |_| | \
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. /~\-=-=-= Intro =-=-=-/~\
  15.  
  16.  
  17. ■ Here is the first tutorial from Fragmentaria!  It is written by
  18. yours truly, Aaron Clemmer, AKA Wikki... Hopefully it will help you 
  19. understand how everyone is making those neat-o firedemos, and possibly 
  20. help you code your own.  The included source was my attempt at making 
  21. one.  I wrote almost all of it, with several exceptions:  the palette, 
  22. and all the ASM (excluding code that changes into mode 03h =).  
  23. Anything that I didn't write was from Kirk A. Baum's public domain 
  24. flame demo source.  And no, I didn't use any of his techniques, I came 
  25. up with them myself. =)
  26.  
  27.  
  28.  
  29. /~\-=-=-= Overview =-=-=-/~\
  30.  
  31.  
  32. ■ In theory, the flame is generated like so:  You have an array that 
  33. reflects the current status of your screen.  You loop through this array, 
  34. reading the color values of the pixels surrounding your current position,
  35. and get the average of those values.  This averaged number goes into 
  36. another array of the same dimensions, positioned directly above the current
  37. position, so that it will rise.  After the entire frame is generated, it is 
  38. dumped to the screen, either one square (4x4 pixels) at a time, or by 
  39. copying the entire array at once.  Then you copy the working array to the 
  40. array that contains what was on your screen, thus updating it, and you 
  41. start over.
  42.  
  43.  
  44.  
  45. /~\-=-=-= Details, Details... =-=-=-/~\
  46.  
  47.  
  48.     ][~-~- Playing With The Palette -~-~][
  49.  
  50. ■ First off, you need a palette suitable for a realistic flame.
  51. What you want to do is set your 256 color palette so that '0' equals 
  52. black, '255' equals white, and everything in-between is a shade of red.  
  53. This obviously gives you a nice "flamey" palette that will do for our 
  54. purposes.  One way to do this (other than use the included palette), is 
  55. to use a paint program that allows you to edit the palette, creating a 
  56. grade from the darkest shade of red to the lightest.  Or, if you can 
  57. settle for using only 64 colors, edit the palette at runtime using a 
  58. loop sorta like this:
  59.  
  60.     int red=0,blue=0,green=0;
  61.     for (red=0,red<64, red++)
  62.     {
  63.       pal_index = red;
  64.       setpalrgb(red, blue, green, pal_index);
  65.     }                     
  66.  
  67. This will increment through the first 64 colors of the palette and 
  68. set them to red colors.  You normally would use the variable 'red' 
  69. in place of 'pal_index', but I was making it more clear what was going 
  70. on.  It is also possible to make a loop that will set all 256 colors to 
  71. red, but this example will do for demonstration purposes.
  72.     
  73.  
  74.     ][~-~- Ye Olde Buffers -~-~][
  75.  
  76. ■ You have two buffers, one which reflects what is currently being 
  77. displayed on the screen, the other is your working buffer.  We'll call 
  78. them CURRENT and WORKING.  You usually set the dimensions to be [80][56].  
  79. Why not just make it the size of your screen?  Speed.  It is much faster 
  80. to use a screenful of four-pixel blocks instead of placing your color 
  81. values at every pixel location on the screen.  Since you have to read 
  82. several pixel values, compute the average, and place the result in the 
  83. proper array each time you go through the loop for each element of the 
  84. array, using a 80x56 buffer is much faster, though a little blocky. =)
  85.  
  86.  
  87.     ][~-~- Generating a Frame O' Flame -~-~][
  88.  
  89. ■ First off, you loop through the two bottom lines of CURRENT, and randomly 
  90. set the value at your X,Y position to either the brightest color value or 
  91. the darkest.  You do this because every time you go through the loop, you 
  92. need to have the flame vary, or it will get quite dull. =)  One thing you 
  93. will notice when you run your program is that the bottom rows are rather 
  94. choppy, instead of being smooth as it is higher up.  This is simply because
  95. the flame at the bottom rows aren't very averaged out yet, and won't improve 
  96. until about 3-5 more rows up.  The easiest way to fix this is to just not 
  97. display the bottom rows on the screen.
  98.  
  99. ■ Once that is done, you run a loop that will start at the bottom position 
  100. of CURRENT (usually [0][56]).  Then you go up towards the top of the buffer, 
  101. getting the averages of the surrounding pixels based on your current 
  102. position in the array.  Afterwords, you place this value at the equivalent 
  103. X,Y position in WORKING.  Of course you do not need to always use the 
  104. surrounding pixels when you are reading the values, you could produce some 
  105. cool effects by reading from different parts of the buffer.
  106.  
  107.  
  108.     ][~-~- Showing It To Our Audience -~-~][
  109.  
  110. ■ So what now?  Dump the entire WORKING array to the screen, then copy it 
  111. to CURRENT, thus reflecting your changes to the screen.  But as you may 
  112. notice, the flame is confined to the two bottom lines of the screen.  Why? 
  113. You need to place your averaged color value at [X][Y-1], which is one line 
  114. above your current position, making the flame rise.  Of course, you can 
  115. place the value anywhere in the array... for example, if you put it above 
  116. and to the right of your position, it will look like the wind is blowing it.
  117.  
  118.  
  119. ■ Now that you got it to rise, you see that your flame goes off the top of 
  120. the screen, instead of fading as it gets closer to the top.  This is where 
  121. the decay variable comes into play.  What you do is after you get your 
  122. average, you write:  IF (COLOR > 1) COLOR--;.  This decreases the color 
  123. values until they are black.  Be sure to try values other than 1 when you 
  124. decrement, for different fade speeds.
  125.  
  126.  
  127.  
  128. /~\-=-=-= Contact Info, Etc. =-=-=-/~\
  129.  
  130.  
  131. ■ So you wanna say something to me, do you?  Whether it says how wonderful
  132. my tutorial is, or gripe mail, send it my way... 
  133.  
  134. Internet E-mail:  AARONC@BBS.GEMLINK.COM
  135.     Note that my internet account expires in September, and there is 
  136.     *small* chance I may not re-subscribe... (horror of horrors!!! =) 
  137.  
  138. Locust Grove BBS:  (540)854-6760
  139.     You can e-mail me here, just address the message 
  140.     to "AARON CLEMMER."
  141.  
  142. Snail-Mail:  Aaron Clemmer
  143.          104 Battle Mountain Rd
  144.          Amissville, Va 22002 USA
  145.